package com.esd.chyl.service.impl;

import com.esd.chyl.mapper.KnowledgeStatisticsMapper;
import com.esd.chyl.model.KnowledgeStatistics;
import com.esd.chyl.service.KnowledgeStatisticsService;
import com.esd.chyl.util.KitService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class KnowledgeStatisticsServiceImpl implements KnowledgeStatisticsService {

    @Autowired
    private KnowledgeStatisticsMapper mapper;

    @Override
    public boolean delete(String id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public boolean insert(KnowledgeStatistics object) {
        if (object == null) {
            return false;
        }
        if (StringUtils.isBlank(object.getId())) {
            object.setId(KitService.getUUID());
        }
        Date now = new Date();
        if (object.getCreateTime() == null) {
            object.setCreateTime(now);
        }
        if (object.getUpdateTime() == null) {
            object.setUpdateTime(now);
        }
        return mapper.insertSelective(object);
    }

    @Override
    public KnowledgeStatistics getById(String id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean update(KnowledgeStatistics object) {
        if (object == null) {
            return false;
        }
        object.setUpdateTime(new Date());
        return mapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public List<KnowledgeStatistics> getAll(KnowledgeStatistics object) {

        return mapper.retrieveList(object);
    }
}
